package com.xzq.erp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync // 开启异步注解功能
public class ThreadPoolConfig {

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 设置线程池参数
        executor.setCorePoolSize(10);// 设置线程池核心线程数
        executor.setMaxPoolSize(20);// 设置线程池最大线程数
        executor.setQueueCapacity(100);// 设置队列容量
        executor.setThreadNamePrefix("erpThreadPool-");// 设置线程池前缀
        executor.initialize();
        return executor;
    }
}
